package sv.mecca.modelo;

import java.sql.SQLException;
import java.util.ArrayList;

import sv.gob.hnr.modelo.Conexion;
import sv.mecca.form.CiclosForm;

public class OperacionesCiclos extends Conexion{

    public void insertarCiclos(CiclosForm c) throws SQLException{
        try {
            st = getConexion().createStatement();
            st.execute("insert into ciclos(expediente_paciente, metilpredmisolona, mofetilo, c11, c12, c13, c21, c22, c23, c31, c32, c33, c41, c42, c43, c51, c52, c53, c61, c62, c63) values(" +
                "'" + c.getExpediente()+ "', " +
                "" + c.getMetilpredmisolona()+ ", " +
                "'" + c.getMofetilo()+ "', " +
                "'" + c.getC11() + "', " +
                "" + c.getC12()+ ", " +
                "'" + c.getC13() + "', " +
                "'" + c.getC21() + "', " +
                "" + c.getC22()+ ", " +
                "'" + c.getC23() + "', " +
                "'" + c.getC31() + "', " +
                "" + c.getC32()+ ", " +
                "'" + c.getC33() + "', " +
                "'" + c.getC41() + "', " +
                "" + c.getC42()+ ", " +
                "'" + c.getC43() + "', " +
                "'" + c.getC51() + "', " +
                "" + c.getC52()+ ", " +
                "'" + c.getC53() + "', " +
                "'" + c.getC61() + "', " +
                "" + c.getC62()+ ", " +
                "'" + c.getC63() + "')");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            }
        finally{
            st.close();
            cn.close();
            }
        c.destroy();
        }
    public CiclosForm modificarCiclos(Integer id) throws SQLException{
        CiclosForm c = new CiclosForm();
        try {
            st = getConexion().createStatement();
            rs = st.executeQuery("select * from ciclos where id = " + id);
            rs.next();
            c.setId(rs.getInt(1));
            c.setExpediente(rs.getString(2));
            c.setMetilpredmisolona(rs.getDouble(3));
            c.setMofetilo(rs.getString(4));
            c.setC11(rs.getString(5));
            c.setC12(rs.getDouble(6));
            c.setC13(rs.getString(7));
            c.setC21(rs.getString(8));
            c.setC22(rs.getDouble(9));
            c.setC23(rs.getString(10));
            c.setC31(rs.getString(11));
            c.setC32(rs.getDouble(12));
            c.setC33(rs.getString(13));
            c.setC41(rs.getString(14));
            c.setC42(rs.getDouble(15));
            c.setC43(rs.getString(16));
            c.setC51(rs.getString(17));
            c.setC52(rs.getDouble(18));
            c.setC53(rs.getString(19));
            c.setC61(rs.getString(20));
            c.setC62(rs.getDouble(21));
            c.setC63(rs.getString(22));
        } catch (Exception e) {
            System.out.println(e.getMessage());
            }
        finally{
            rs.close();
            st.close();
            cn.close();
            return c;
            }
        }
    public void actualizarCiclos(CiclosForm c, Integer id) throws SQLException{
        try {
            st = getConexion().createStatement();
            st.executeUpdate("update ciclos set " +
                "expediente_paciente = '" + c.getExpediente()+ "', " +
                "metilpredmisolona = '" + c.getMetilpredmisolona()+ "', " +
                "mofetilo = '" + c.getMofetilo()+ "', " +
                "c11 = '" + c.getC11() + "', " +
                "c12 = " + c.getC12() + ", " +
                "c13 = '" + c.getC13() + "', " +
                "c21 = '" + c.getC21() + "', " +
                "c22 = " + c.getC22() + ", " +
                "c23 = '" + c.getC23() + "', " +
                "c31 = '" + c.getC31() + "', " +
                "c32 = " + c.getC32() + ", " +
                "c33 = '" + c.getC33() + "', " +
                "c41 = '" + c.getC41() + "', " +
                "c42 = " + c.getC42() + ", " +
                "c43 = '" + c.getC43() + "', " +
                "c51 = '" + c.getC51() + "', " +
                "c52 = " + c.getC52() + ", " +
                "c53 = '" + c.getC53() + "', " +
                "c61 = '" + c.getC61() + "', " +
                "c62 = " + c.getC62() + ", " +
                "c63 = '" + c.getC63() + "' " +
                "where id = " + id);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            }
        finally{
            st.close();
            cn.close();
            }
        c.destroy();
        }
    public void EliminarCiclos(Integer id) throws SQLException{
        try {
            st = getConexion().createStatement();
            st.execute("delete from ciclos where id = " + id);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            }
        finally{
            st.close();
            cn.close();
            }
        }
    public ArrayList<CiclosForm> listado() throws SQLException{
        ArrayList<CiclosForm> ciclos = null;
        try {
            st = getConexion().createStatement();
            rs = st.executeQuery("select * from ciclos");
            ciclos = new ArrayList<CiclosForm>();
            while (rs.next()) {
                CiclosForm c = new CiclosForm(rs.getInt(1), rs.getString(2), rs.getDouble(3), rs.getString(4),
                        rs.getString(5), rs.getDouble(6), rs.getString(7),
                        rs.getString(8), rs.getDouble(9), rs.getString(10),
                        rs.getString(11), rs.getDouble(12), rs.getString(13),
                        rs.getString(14), rs.getDouble(15), rs.getString(16),
                        rs.getString(17), rs.getDouble(18), rs.getString(19),
                        rs.getString(20), rs.getDouble(21), rs.getString(22));
                ciclos.add(c);
                }
            rs.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
            }
        finally{
            st.close();
            cn.close();
            return ciclos;
            }
        }
    }